var a = getApp();

Page({
    data: {
        array: [ "男", "女" ],
        sex: "0",
        pickerValue: [ 0, 0, 0 ],
        form: {
            sex: "1",
            user_name: "",
            phone: "",
            address: "",
            dealer_user_id: ""
        }
    },
    onLoad: function(a) {
        a.dealer_uid && this.setData({
            dealer_uid: a.dealer_uid
        }), this._initAddressInfo(), this.getData();
    },
    phoneBtn: function(a) {
        wx.navigateTo({
            url: "/packageA/member/editmobile/editmobile"
        });
    },
    bindPickerChange: function(a) {
        console.log(a);
        var e = a.detail.value;
        this.setData({
            sex: e
        });
    },
    addressShowbtn: function() {
        this.setData({
            addressShow: !0
        });
    },
    bindChange: function(a) {
        var e = a.detail.value;
        this.data.pickerValue[0] != e[0] && (e[1] = 0, e[2] = 0), this.data.pickerValue[1] != e[1] && (e[2] = 0), 
        this.setData({
            "pickerValue[0]": e[0],
            "pickerValue[1]": e[1],
            "pickerValue[2]": e[2]
        }), this._initAddressInfo();
    },
    _closeDateLw: function() {
        this.setData({
            addressShow: !1
        });
    },
    resultAdd: function() {
        var a = this.data.selectAddressData, e = a[0].name + " " + a[1].name + " " + a[2].name;
        this.setData({
            addressName: e,
            provice: a[0].name,
            city: a[1].name,
            district: a[2].name
        }), this.setData({
            "applyModel.provinceId": a[0].id,
            "applyModel.cityId": a[1].id,
            "applyModel.districtId": a[2].id,
            addressShow: !1
        }), console.log(this.data.applyModel, this.data.addressName);
    },
    _initAddressInfo: function() {
        var e = this;
        wx.getStorage({
            key: "provinceData",
            success: function(a) {
                console.log("地址信息准备就绪"), e._getProvinceData();
            },
            fail: function(t) {
                console.log("省fail"), a._getNetWork({
                    url: a.getNetAddresss("member.member-address.address"),
                    success: function(a) {
                        var t = a.data, s = t.data.province, i = t.data.city, d = t.data.district;
                        wx.setStorage({
                            key: "provinceData",
                            data: s
                        }), wx.setStorage({
                            key: "cityData",
                            data: i
                        }), wx.setStorage({
                            key: "districtData",
                            data: d
                        }), e._initAddressInfo();
                    },
                    fail: function(a) {},
                    state: !0
                });
            }
        });
    },
    _getProvinceData: function() {
        var a = this;
        wx.getStorage({
            key: "provinceData",
            success: function(e) {
                console.log("省读取成功", e.data), a.setData({
                    provinceData: e.data
                }), a.setData({
                    "selectAddressData[0].name": e.data[a.data.pickerValue[0]].areaname,
                    "selectAddressData[0].id": e.data[a.data.pickerValue[0]].id,
                    "selectAddressData[0].index": a.data.pickerValue[0]
                }), a._getCityData();
            }
        });
    },
    _getCityData: function() {
        var a = this.data.selectAddressData[0];
        console.log("城市", "_data", a);
        var e = this;
        wx.getStorage({
            key: "cityData",
            success: function(t) {
                console.log("城市读取成功", t);
                for (var s = [], i = 0; i < t.data.length; i++) t.data[i].parentid == a.id && s.push(t.data[i]);
                console.log("城市数据筛选", s), e.setData({
                    cityData: s
                }), e.setData({
                    "selectAddressData[1].name": s[e.data.pickerValue[1]].areaname,
                    "selectAddressData[1].id": s[e.data.pickerValue[1]].id,
                    "selectAddressData[1].index": e.data.pickerValue[1]
                }), e._getDistrictData();
            }
        });
    },
    _getDistrictData: function() {
        var a = this.data.selectAddressData[1];
        console.log("地区", "_data", a), console.log(a);
        var e = this;
        wx.getStorage({
            key: "districtData",
            success: function(t) {
                console.log("地区读取成功");
                for (var s = [], i = 0; i < t.data.length; i++) t.data[i].parentid == a.id && s.push(t.data[i]);
                console.log("地区数据筛选", s), e.setData({
                    districtData: s
                }), console.log("districtData", s), e.setData({
                    "selectAddressData[2].name": s[e.data.pickerValue[2]].areaname,
                    "selectAddressData[2].id": s[e.data.pickerValue[2]].id,
                    "selectAddressData[2].index": e.data.pickerValue[2]
                }), console.log("over", e.data.selectAddressData);
            }
        });
    },
    iuser_name: function(a) {
        console.log(a.detail.value);
        var e = a.detail.value;
        this.setData({
            "form.user_name": e
        });
    },
    onReady: function() {},
    onShow: function() {
        this.getData();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    confirm: function() {
        var e = this.data.form;
        if (e.address = this.data.addressName, e.sex = 1 == this.data.form.sex ? "男" : "女", 
        console.log(e), a._isTextEmpty(this.data.form.user_name)) wx.showToast({
            title: "请输入姓名",
            icon: "none",
            duration: 1e3
        }); else if (a._isTextEmpty(this.data.addressName)) wx.showToast({
            title: "请选择地区",
            icon: "none",
            duration: 1e3
        }); else {
            var t = a.getNetAddresss("plugin.energy-cabin.frontend.dealer-terminal.add-member-info");
            a._getNetWork({
                url: t,
                data: e,
                success: function(a) {
                    var e = a.data;
                    1 === e.result && wx.showToast({
                        title: e.msg,
                        duration: 1e3,
                        icon: "none",
                        success: function() {
                            setTimeout(function() {
                                wx.navigateBack({
                                    delta: 1
                                });
                            }, 1500);
                        }
                    });
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        }
    },
    getData: function() {
        var e = this, t = {
            dealer_uid: this.data.dealer_uid
        }, s = a.getNetAddresss("plugin.energy-cabin.frontend.dealer-terminal.show-member-page");
        a._getNetWork({
            url: s,
            data: t,
            success: function(a) {
                var t = a.data;
                1 === t.result && e.setData({
                    "form.phone": t.data.member.mobile,
                    "form.dealer_user_id": t.data.dealer_member.uid,
                    "form.user_name": t.data.member.nickname,
                    "form.name": t.data.dealer_member.nickname,
                    "form.invite_mobile": t.validate_page.invite_mobile
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    }
});